package dynamicproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

/**
 * @author gaopeng
 * @date 2019/12/8 8:26 下午
 */
public class Client {
    public static void main1(String[] args) {
        GamePlayer gamePlayer = new GamePlayer();
        InvocationHandler handler = new MyHandler(gamePlayer);
        ClassLoader classLoader = gamePlayer.getClass().getClassLoader();
        IGamePlayer proxy = (IGamePlayer)Proxy.newProxyInstance(classLoader, gamePlayer.getClass().getInterfaces(), handler);
        proxy.login("zhangsan","123");
        proxy.killBoss();
        proxy.upgrade();

    }

    public static void main(String[] args) {
        IGamePlayer proxy = new DynamicProxy(new MyAdvice()).newProxyInstance(GamePlayer.class);
        proxy.login("zhangsan","123");
        /*proxy.killBoss();
        proxy.upgrade();*/
        System.out.println(proxy.toString());

    }
}
